import 'dart:convert';
import 'dart:io';

import 'package:sl_fast_dev/sl_fast_dev.dart';
import 'package:test/test.dart';

const String TEMPLTEKIT = './example/templete_kit.json';

void main() {
  group('A group of tests', () {
    setUp(() {
      SLFastDevConfig().prefix = 'SEG';
      SLFastDevConfig().hasVM = true;
    });

    test('First Test', () async {
      var docStr = File(TEMPLTEKIT).readAsStringSync();

      var path = './example/demo/demo/Classes/';
      var dir = Directory(path);

      if (dir.existsSync()) {
        dir.deleteSync(recursive: true);
        await dir.create();
      }

      SLNodeManager(docStr).outFiles.forEach((key, value) {
        File('$path$key').writeAsStringSync(value);
      });
    });

    test('Doclever to RAC', () async {
      var source = File(
              '/Users/sam/Desktop/sl_demo/sl_demo/Classes/doclever/SEGRootManager_ViewModel.json')
          .readAsStringSync();
      Map jsonData = json.decode(source);

      var docStr = File(TEMPLTEKIT).readAsStringSync();

      var path = './example/demo/demo/Classes/';
      var dir = Directory(path);

      if (dir.existsSync()) {
        dir.deleteSync(recursive: true);
        await dir.create();
      }

      var nodeManager = SLNodeManager(docStr, docMap: jsonData);

      nodeManager.outFiles.forEach((key, value) {
        File('$path$key').writeAsStringSync(value);
      });
    });
  });
}
